package com.yzw.hello.controller.system;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yzw.hello.model.pojos.utls.AjaxMessage;
import com.yzw.hello.service.system.role.RoleService;

@Controller
@RequestMapping("/role")
public class RoleController {

	@Autowired
	private RoleService roleService;
	
	@RequestMapping("")
	public String role(Model model) {
		model.addAttribute("roles", roleService.getList());
		return "system/role/role";
	}
	
	@RequestMapping("/users")
	@ResponseBody
	public AjaxMessage saveRoleUsers(HttpServletRequest request) {
		 Integer id = Integer.parseInt(request.getParameter("id"));
		 String userIds = request.getParameter("userIds");
		return roleService.saveRoleUsers(id, userIds);
	}
	
	@RequestMapping("/userList")
	public String userList(Model model,HttpServletRequest request) {
		Integer id = Integer.parseInt(request.getParameter("id"));
		model.addAttribute("users", roleService.getCheckedList(id));
		return "system/user/userList";
	}
	
}
